#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/9/24 22:05
# @Author  : AshJo
# @Desc    : property装饰器
# @Filename: property.py
# @Version : v1.0
"""


class Goods:
    discount = 0.8

    def __init__(self, name, origin_price):
        self.name = name
        self.__price = origin_price

    @property   # 把类中的方法装饰成属性
    def price(self):
        return self.discount * self.__price

    @price.setter
    def price(self, new_price):
        if isinstance(new_price, int):
            self.__price = new_price


apple = Goods('apple', 5)
print(apple.price)  # 调用的是被@property装饰的price

apple.price = 10    # 调用的是被setter装饰的price
print(apple.price)
